# -*- coding: utf-8 -*-

from odoo_contrib.exceptions import BaseOdooException


class WechatMiniAppException(BaseOdooException):
    # category
    # miniapp: 20
    category = 'wechat-miniapp'

    # sub category:
    #   - miniapp.entry 10
    #   - auth.configuration 20
    #   - redis.configuration 30
    #   - access_token.retrieving 40
    #   - qrcode.generation 50
    #   - wechat.decryption 60
    #   - wechat.template_message 70
    #   - wechat.mp.menu.create 80
    #   - wechat.mp.jssdk.config 90

    co_msg_mapping = {
        201001: {
            # No mini app site found
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201002: {
            # No mini app setting found
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201003: {
            # Missing mini app parameters: app id
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201004: {
            # Missing mini app parameters: app secret
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201005: {
            # app entry found, but not a mp-app entry
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201006: {
            # Missing np app parameters: mp token
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201010: {
            # app entry found, but missing settings
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        201011: {
            # app entry found, but type unknown
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'miniapp.entry',
        },
        202001: {
            # Missing auth configuration parameters: serialization key or expiration
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'auth.configuration',
        },
        203001: {
            # redis connection error
            'message': 'Internal error',
            'http_code': 500,
            'sub_category': 'redis.configuration',
        },
        304001: {
            'message': 'Tencent returned error',
            'http_code': 500,
            'sub_category': 'access_token.retrieving'
        },
        304002: {
            'message': 'Missing access token in tencent returned data',
            'http_code': 400,
            'sub_category': 'access_token.retrieving'
        },
        304050: {
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'access_token.retrieving'
        },
        304051: {
            # loading access token from redis
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'access_token.retrieving'
        },
        304052: {
            # persisting access token from redis
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'access_token.retrieving'
        },
        305001: {
            'message': 'Illegal char in scene',
            'http_code': 400,
            'sub_category': 'qrcode.generation'
        },
        305002: {
            'message': 'Retrieving access token failed',
            'http_code': 500,
            'sub_category': 'qrcode.generation'
        },
        305003: {
            'message': 'Wechat returns error',
            'http_code': 500,
            'sub_category': 'qrcode.generation',
        },
        305050: {
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'qrcode.generation',
        },
        306050: {
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'wechat.decryption',
        },
        307001: {
            'message': 'data format error',
            'http_code': 400,
            'sub_category': 'wechat.template_message'
        },
        307002: {
            'message': 'Missing required fields in data',
            'http_code': 400,
            'sub_category': 'wechat.template_message'
        },
        307003: {
            'message': 'Specified template not exists',
            'http_code': 404,
            'sub_category': 'wechat.template_message'
        },
        307004: {
            'message': 'Specified miniapp not exists',
            'http_code': 404,
            'sub_category': 'wechat.template_message'
        },
        308050: {
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'wechat.mp.menu.create',
        },
        309001: {
            'message': 'empty url',
            'http_code': 400,
            'sub_category': 'wechat.mp.jssdk.config',
        },
        309050: {
            'message': 'Unexpected exception',
            'http_code': 500,
            'sub_category': 'wechat.mp.jssdk.config',
        },
    }
